﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DeskBugtracker
{
    public partial class ConfigurationsManager : Form
    {
        public ConfigurationsManager()
        {
            InitializeComponent();
        }

        private void ConfigurationsManager_Load(object sender, EventArgs e)
        {
        }

        void tmp_FormClosed(object sender, FormClosedEventArgs e)
        {
            Form tmp = sender as Form;

            if (tmp != null)
            {
                tabConf.TabPages.RemoveByKey(tmp.Name);
            }
            else
                throw new NotImplementedException();
        }

        public string Options
        {
            get { return ""; }
        }

        private void lstConfiguration_DoubleClick(object sender, EventArgs e)
        {
            ListBox lb = sender as ListBox;

            if(tabConf.TabPages.ContainsKey(lb.SelectedItem as String))
            {
                tabConf.SelectedTab = tabConf.TabPages[lb.SelectedItem as String];
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            int i = 0;
            string tabKey = "NewConfiguration" + i.ToString();

            while (lstConfiguration.Items.Contains(tabKey))
            {
                ++i;
                tabKey = "NewConfiguration" + i.ToString();
            }

            {
                /*MantisCommon.MantisOptions tmp = new MantisCommon.MantisOptions("URL=http://192.168.1.125/mantisbt/api/soap/mantisconnect.php;Username=administrator;Password=壨⹀䠂릨蜠螨;");
                tmp.ShowDialog();/*/
                /*tmp.TopLevel = false;
                tmp.Name = tabKey;
                tmp.FormBorderStyle = FormBorderStyle.None;
                tmp.FormClosed += new FormClosedEventHandler(tmp_FormClosed);
                tmp.Show();
                tmp.WindowState = FormWindowState.Maximized;
                tabConf.TabPages.Add(tabKey, "New Configuration " + i.ToString());
                tabConf.TabPages[tabKey].Controls.Add(tmp);

                lstConfiguration.Items.Add(tabKey);
                tabConf.SelectedTab = tabConf.TabPages[tabKey];//*/
            }
        }

        private void lstConfiguration_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListBox lb = sender as ListBox;

            if (tabConf.TabPages.ContainsKey(lb.SelectedItem as String))
            {
                tabConf.SelectedTab = tabConf.TabPages[lb.SelectedItem as String];
            }
        }
    }
}
